from uitls.get_by_local import GetByLocal
from base.base_driver import BaseDriver
import time


class ActionMethod:
    def __init__(self):
        base_driver = BaseDriver()
        self.driver = base_driver.android_driver(0)
        self.get_by_local = GetByLocal(self.driver)

    def inputs(self, *args):
        '''
        输入框输入元素
        :key,vlaue
        '''
        # *args返回的是个list
        element = self.get_by_local.get_element(args[0])
        if element == None:
            return args[0], 'action_methond的input的元素没找到'
        element.send_keys(args[1])

    def on_click(self, *args):
        '''
        点击元素
        '''
        element = self.get_by_local.get_element(args[0])
        if element == None:
            return args[0], 'action_methond的on_click的元素没找到'
        element.click()

    def sleep_time(self, *args):
        print('sleep_time-------------', args[0])
        '''
        等待时间
        '''
        time.sleep(int(args[0]))

    # 获取屏幕宽高
    def get_size(self, *args):
        size = self.driver.get_window_size()
        width = size['width']
        height = size['height']
        return width, height

    # 左滑
    def swipe_left(self, *args):
        x1 = self.get_size()[0] / 10 * 8
        y1 = self.get_size()[1] / 2
        x = self.get_size()[0] / 10
        self.driver.swipe(x1, y1, x, y1)

    # 向右滑动
    def swipe_right(self, *args):
        x1 = self.get_size()[0] / 10
        y1 = self.get_size()[1] / 2
        x = self.get_size()[0] / 10 * 8
        self.driver.swipe(x1, y1, x, y1)

    # 上滑
    def swipe_up(self, *args):
        x1 = self.get_size()[0] / 2
        y1 = self.get_size()[1] / 10 * 8
        y = self.get_size()[1] / 10
        self.driver.swipe(x1, y1, x1, y)

    # 下滑
    def swipe_down(self, *args):
        x1 = self.get_size()[0] / 2
        y1 = self.get_size()[1] / 10 * 8
        y = self.get_size()[1] / 10
        self.driver.swipe(x1, y1, x1, y)

    def get_element(self, *args):
        element = self.get_by_local.get_element(args[0])
        if element == None:
            print('-------action_methond的get_element的元素没找到------')
            return None
        return element
